<?php 
session_start();
$websitePermission = 0;
include "headerVerify.php";
include "connect.php"; 

if (isset($_POST['statusSelect'])) {$_SESSION['selectedStatus'] = $_POST['statusSelect'];}


if ($_SESSION['selectedStatus'] != "All") {$WHEREstatus = "WHERE status = '".$_SESSION['selectedStatus']."' LIMIT 50";}
if ($_SESSION['selectedStatus'] == "") {$WHEREstatus = "WHERE status = 'New' LIMIT 50";}
//if ($_SESSION['selectedStatus'] == "All") {$WHEREstatus = " LIMIT 50";}

//logs user out to main log in screen if they havent permissions to view this page
if ($_SESSION['userName'] == "")

{
header('Location: index.php');
}

?>

<html>
<head>
<title>MyAccount | <?php echo $_SESSION['websiteAddress'] ?></title>

<link href="css/adminMain.css" rel="stylesheet" type="text/css">
<link href="css/customerFeedback.css" rel="stylesheet" type="text/css">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">


</head>

<body >

<div id="adminPageContainer" onClick="function add(text)">

<?php include "header.php" ?>

<?php include "navigation.php" ?>

<div id="feedbackContent">

<div id="feedbackOptions">

	<form action="<?php $_SERVER['PHP_SELF'] ?>" method="post" name="feedbackOptions">

	<label>Status</label>
    
    

	<select id="statusSelect" name="statusSelect">
      <option value="All" <?php if ($_SESSION['selectedStatus'] == "All") {echo "selected";} else {echo "";} ?>>All (50 limit)</option>
	  <option value="New" <?php if ($_SESSION['selectedStatus'] == "New") {echo "selected";} else {echo "";} ?>>New feedback</option>
	  <option value="Accepted" <?php if ($_SESSION['selectedStatus'] == "Accepted") {echo "selected";} else {echo "";} ?>>Accepted feedback</option>
	  <option value="Rejected" <?php if ($_SESSION['selectedStatus'] == "Rejected") {echo "selected";} else {echo "";} ?>>Rejected feedback</option>
	</select>
    
    <input name="submitOptions" type="submit" id="submitOptions" value="Refresh">

	</form>

</div>

<table width="500" border="1" cellpadding="3">
  <tr>
    <th scope="col">ID</th>
    <th scope="col">Date</th>
    <th scope="col">Customer</th>
    <th scope="col">Type</th>
    <th scope="col">Feedback</th>
    <th scope="col">Accepted</th>
    <th scope="col">Accept/Reject</th>
  </tr>

<?php
//Writes out hosting details if user has permission to view it
//Permission level
$hostingPermission = 6;
//Permission check##

$query = "SELECT * FROM feedback ";

$query .= $WHEREstatus;

$result = mysql_query($query);



while($row = mysql_fetch_array($result))
  {
	  
if($row['status'] == "New")
{$form = '

<form action="acceptFeedback.php" method="post" name="feedbackStatus">
<input name="feedbackID" type="hidden" value="'.$row['id'].'">
<input id="button" name="acceptFeedback" type="submit" value="Accept">
</form>
<form action="rejectFeedback.php" method="post" name="feedbackStatus">
<input name="feedbackID" type="hidden" value="'.$row['id'].'">
<input id="button" name="rejectFeedback" type="submit" value="Reject">
</form>
';}
 
if($row['status'] == "Rejected")
{$form = '

<form action="acceptFeedback.php" method="post" name="feedbackStatus">
<input name="feedbackID" type="hidden" value="'.$row['id'].'">
<input id="button" name="acceptFeedback" type="submit" value="Accept">
</form>
';}

if($row['status'] == "accepted")
{$form = '

<form action="rejectFeedback.php" method="post" name="feedbackStatus">
<input name="feedbackID" type="hidden" value="'.$row['id'].'">
<input id="button" name="acceptFeedback" type="submit" value="Reject">
</form>
';}
 
 echo"<tr>";
 	echo"<td>".$row['id']."</td>";
    echo"<td>".$row['date']."</td>";
    echo"<td>
	
	<form action='updateCustomer.php' method='post' name='updateCustomer'>
	<input name='feedbackID' type='hidden' value='".$row['id']."'>
	<input id='nameField' name='customerName' value='".$row['customer']."' type='text'>
	<input id='button' name='updateCustomer' type='submit' value='Update'>
	</form>
	
		</td>";
    echo"<td>".$row['type']."</td>";
    echo"<td>".$row['feedback']."</td>";
	echo"<td>".$row['status']."</td>";
	echo'<td>'.$form.'</td>';
	
 echo" </tr>";
  
  }

?>

</table>


</div>

</div>
</body>
</html>